package com.wctj.api.business.common.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wctj.api.base.entity.DdwxRechargeOrder;
import com.wctj.api.base.utils.InstanceConvertUtil;
import com.wctj.api.business.common.dao.DdwxRechargeOrderMapper;
import com.wctj.api.business.common.dto.DdwxMemberDTO;
import com.wctj.api.business.common.dto.DdwxPayOrderDTO;
import com.wctj.api.business.common.dto.DdwxRechargeOrderDTO;
import com.wctj.api.business.common.service.DdwxRechargeOrderService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

@Service
public class DdwxRechargeOrderServiceImpl extends ServiceImpl<DdwxRechargeOrderMapper, DdwxRechargeOrder> implements DdwxRechargeOrderService {


    @Override
    @Transactional(rollbackFor = {Exception.class})
    public DdwxRechargeOrderDTO addCmbRechargeRecord(DdwxMemberDTO ddwxMemberDTO, DdwxPayOrderDTO ddwxPayOrderDTO, String amount) {
        DdwxRechargeOrder rechargeOrder = new DdwxRechargeOrder();
        rechargeOrder.setAid(ddwxMemberDTO.getAid());
        rechargeOrder.setMid(Math.toIntExact(ddwxMemberDTO.getId()));
        rechargeOrder.setMoney(new BigDecimal(amount));
        rechargeOrder.setOrdernum(ddwxPayOrderDTO.getOrdernum());
        rechargeOrder.setCreatetime((int) System.currentTimeMillis());
        rechargeOrder.setStatus(ddwxPayOrderDTO.getStatus());
        rechargeOrder.setPayorderid(ddwxPayOrderDTO.getId());
        rechargeOrder.setPaytypeid(ddwxPayOrderDTO.getPaytypeid());
        rechargeOrder.setPaytype(ddwxPayOrderDTO.getPaytype());
        rechargeOrder.setPaynum(ddwxPayOrderDTO.getPaynum());
        rechargeOrder.setPaytime((int) System.currentTimeMillis());
        rechargeOrder.setPlatform(ddwxPayOrderDTO.getPlatform());
        baseMapper.insert(rechargeOrder);
        return InstanceConvertUtil.convertObject(rechargeOrder, DdwxRechargeOrderDTO.class);
    }
}
